<template>
	<view class="content">
		<navigation :title="'搜索'" class="navigation"></navigation>
		<view class="text-area">
			<view class="serch neibinaju">
				<view class="left">
					<span class="iconfont" style="">&#xe74f;</span>
				</view>
				<view class="right">
					<input type="text" placeholder="搜索歌曲" v-model="searchValue" @input="getSearchSuggest" />
				</view>
			</view>
			<view class="listR">
				<h3 v-if="list!=null">热榜</h3>
				<ul else>
					<li v-for="(item,index) in suggestList" :key="index" @click="navPlayer(item.searchWord)">
						{{index+1}}:{{item.searchWord}}
					</li>
				</ul>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		searchHot,
		searchWord as searchWordApi,
		searchSuggest
	} from "../../request/request.js"

	export default {
		data() {
			return {
				title: 'Hello',
				searchValue: "",
				list: [], // 将 list 属性定义在 data 中
				list2: [],
				suggestList: [],
			}
		},
		onLoad(option) {
			searchHot().then((res)=>{
				this.suggestList=res.data.data
			});
		},
		methods: {
			navPlayer(searchWord) {
				searchWordApi(searchWord).then((res) => {
					// this.list2 = res.data.data; // 将获取到的数据赋值给 list
					console.log(res.data.result)
					// uni.navigateTo({
					// 	url:'/pages/player/player?songId='+res.data.result.songs[0].album.id,
					// })
				})
			},
			getSearchSuggest() {
				if (this.searchValue.trim() === "") {
					this.suggestList = []; // 清空搜索建议列表
					return;
				}
				searchWord(this.searchValue).then((res) => {
					// this.suggestList = res.data.data; // 将获取到的搜索建议赋值给 suggestList
					
					console.log(this.res.data.result.songs);
				});
			},
		}
	}
</script>

<style>
	* {
		margin: 0;
		padding: 0;
	}

	ul {
		list-style: none;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: whitesmoke;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 1500rpx;
		background-color: brown;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.navigation {
		width: 100%;
		padding: 50rpx 0;
		background-color: brown;
	}

	.neibinaju {
		margin-bottom: 15rpx;
	}

	.serch {
		display: flex;
		margin: 0 auto;
		box-sizing: border-box;
		position: relative;
		width: 95%;
		height: 80rpx;
		padding-left: 10rpx;
		line-height: 80rpx;
		border-radius: 50rpx;
		background-color: white;
		background-color: #f7f7f7;
	}

	.serch .iconfont {
		font-size: 40rpx;
	}

	.serch input {
		height: 80rpx;
		margin-left: 10rpx;
	}

	.listR {
		width: 93%;
		margin: 30rpx auto;
		color: white;
		text-align: left;
	}

	.listR li {
		padding: 10rpx;
	}

	.listR h3 {
		padding: 10rpx;
		font-size: 50rpx;
	}
</style>
